//
//  ZyaPayFormVC.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2021/3/23.
//  Copyright © 2021 zwb. All rights reserved.
//

import UIKit
 
import Eureka
class ZyaPayFormVC: KSFormViewController,refreshable {
    
    var money:PriceRow!
  
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "付款申请"
        
         
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "保存", style: .done, target: self, action: #selector(saveAction))
        self.performRow()
        
    }
    
    @objc func saveAction() {
        
        guard doubleTran(self.money.value) > 0 else {
            KSToast("输入价格")
            return
        }
        
        alertUtil(self, title: "确认新增付款申请？", operateS: [nameAction(name: "确认", action: { (_) in
            KSNetwork.shared.doRequest(API.payApplySave(date: Date.today, payMoney: self.money.value.unwrap)) { (data:BaseResult<OperateResult>) in
                if data.flag == TRUE {
                    self.navigationController?.popViewController(animated: true)
                    if let clo = self.refreshClosure {
                        clo()
                    }
                } else {
                    KSToast(data.message.unwrap)
                }
            }
        })])
      
    }
 
    
    func performRow () {
        
        
        let formatter = DateFormatter()
        formatter.locale = .current
        formatter.dateStyle = .short
        formatter.dateFormat = "yyyy-MM-dd"
        
        
        // Do any additional setup after loading the view.
        self.form +++ Section()
            <<< TextRow () {
                $0.title = "客户名称:"
                $0.value = USERINFO.kfName.unwrap
                $0.disabled = true
            }
            
            <<< PriceRow ("money") {
                $0.title = "付款金额(元):"
                $0.placeholder = "请输入付款金额"
            }
         
            <<< TextRow () {
                $0.title = "申请时间:"
                $0.value = Date.today
                $0.disabled = true
            }
             
        self.money = self.form.rowBy(tag: "money")
         
              
    }

    
    
    
    
    
}
